package com.youbug.mall.member_ums.service.impl;

import com.youbug.mall.member_ums.entity.UmsMemberReceiveAddress;
import com.youbug.mall.member_ums.mapper.UmsMemberReceiveAddressMapper;
import com.youbug.mall.member_ums.service.IUmsMemberReceiveAddressService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import com.youbug.common.vo.QueryVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 会员收货地址 服务实现类
 * </p>
 *
 * @author youbug
 * @since 2024-07-06
 */
@Service
public class UmsMemberReceiveAddressServiceImpl extends ServiceImpl<UmsMemberReceiveAddressMapper, UmsMemberReceiveAddress> implements IUmsMemberReceiveAddressService {

        @Override
        public IPage<UmsMemberReceiveAddress> getUmsMemberReceiveAddressPage(QueryVo<UmsMemberReceiveAddress> queryVo) {

        Page<UmsMemberReceiveAddress> paramPage = new Page<>();

        paramPage.setCurrent(queryVo.getCurrentPage());

        paramPage.setSize(queryVo.getPageSize());

        QueryWrapper<UmsMemberReceiveAddress> wrapper = new QueryWrapper<>();

        UmsMemberReceiveAddress umsMemberReceiveAddress = queryVo.getPayload();

        if(!ObjectUtils.isEmpty(umsMemberReceiveAddress)){
                    if(umsMemberReceiveAddress.getId()!=null){
                    wrapper.gt("id", umsMemberReceiveAddress.getId());
                    }
                    if(umsMemberReceiveAddress.getMemberId()!=null){
                    wrapper.gt("member_id", umsMemberReceiveAddress.getMemberId());
                    }
            if(StringUtils.hasText(umsMemberReceiveAddress.getName())){
                wrapper.eq("name", umsMemberReceiveAddress.getName());
            }
            if(StringUtils.hasText(umsMemberReceiveAddress.getPhone())){
                wrapper.eq("phone", umsMemberReceiveAddress.getPhone());
            }
            if(StringUtils.hasText(umsMemberReceiveAddress.getPostCode())){
                wrapper.eq("post_code", umsMemberReceiveAddress.getPostCode());
            }
            if(StringUtils.hasText(umsMemberReceiveAddress.getProvince())){
                wrapper.eq("province", umsMemberReceiveAddress.getProvince());
            }
            if(StringUtils.hasText(umsMemberReceiveAddress.getCity())){
                wrapper.eq("city", umsMemberReceiveAddress.getCity());
            }
            if(StringUtils.hasText(umsMemberReceiveAddress.getRegion())){
                wrapper.eq("region", umsMemberReceiveAddress.getRegion());
            }
            if(StringUtils.hasText(umsMemberReceiveAddress.getDetailAddress())){
                wrapper.eq("detail_address", umsMemberReceiveAddress.getDetailAddress());
            }
            if(StringUtils.hasText(umsMemberReceiveAddress.getAreacode())){
                wrapper.eq("areacode", umsMemberReceiveAddress.getAreacode());
            }
        }
        if(!ObjectUtils.isEmpty(queryVo.getStartTime())){
            wrapper.gt("create_time", queryVo.getStartTime());
        }
        if(!ObjectUtils.isEmpty(queryVo.getEndTime())){
            wrapper.lt("create_time", queryVo.getEndTime());
        }
        wrapper.orderByDesc("create_time");

        Page<UmsMemberReceiveAddress> page = this.page(paramPage, wrapper);

        return page;
        }

       /* @Transactional(transactionManager = "transactionManagerXXX", rollbackFor = Exception.class)
        public boolean saveBatch(Collection<UmsMemberReceiveAddress> entityList) {
        return saveBatch(entityList, DEFAULT_BATCH_SIZE);
        }
        */
}
